package com.hou.serviceorder.controller;

import com.hou.serviceorder.config.ApiRateLimit;
import com.hou.serviceorder.po.Order;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.lang.annotation.Inherited;
import java.util.concurrent.TimeUnit;

@RestController
@RequestMapping("/order")
@RefreshScope  // 支付动态刷新
public class OrderController {

    @Value("${url}")
    private String url;

    @GetMapping("/config")
    public String getUrl() {
        System.out.println("----------"+url);
        return url;
    }

    @ApiRateLimit(value = 5)
    @GetMapping("/name")
    public String getOrderName(){
        System.out.println("-----进入getOrder方法------");
        return "order";
    }

    @ApiRateLimit(value = 5)
    @GetMapping("/order")
    public Order getOrder(String id) throws InterruptedException {
        System.out.println("-----进入getOrder方法------");
        TimeUnit.SECONDS.sleep(2);
        return new Order(id,"侯征");
    }

    @PostMapping("/insert")
    public Order insertOrder(@RequestBody Order order){
        return order;
    }
}
